# -*- coding: utf-8 -*- 
"""
========================================================================================================================
@project : modelscope-sanic
@file: table_structure
@Author: mengying
@email: 652044581@qq.com
@date: 2023/4/3 15:21
@desc: 表格图片的教会点检测
========================================================================================================================
"""


class SingletonDecorator:
    def __init__(self, cls):
        self.cls = cls
        self._instance = None

    def __call__(self, *args, **kwargs):
        if self._instance is None:
            self._instance = self.cls(*args, **kwargs)
        return self._instance


@SingletonDecorator
class TableRecognition:

    def __init__(self) -> None:
        from modelscope.pipelines import pipeline
        from modelscope.utils.constant import Tasks
        self.model = pipeline(Tasks.table_recognition, model='damo/cv_dla34_table-structure-recognition_cycle-centernet')
        print("table_recognition loaded successfully")


if __name__ == '__main__':
    result = TableRecognition().model('https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/table_recognition.jpg')
    print(result)
